import Vue from "vue";
import db from "../datastore";
import VueI18n from "vue-i18n";
import messages from "./i18n"; // 语言：中/英
import App from "./App";
import router from "./router";
import store from "./store";
import "./utils/initialization";

import * as filters from "./utils/filters"; // 全局 filters

import "./assets/icons"; // 导入svg图标
// import './utils/permission' // 许可控制

import ElementUI from "element-ui";
import "iview/dist/styles/iview.css";
import "element-ui/lib/theme-chalk/index.css";
import "../../static/theme/index.css";
import "./global.scss";
import LemonIMUI from "lemon-imui";
import "lemon-imui/dist/index.css";
// 语音提醒
import { voicePrompt } from "./utils/voice"

Vue.use(LemonIMUI);
Vue.use(ElementUI);
Vue.use(VueI18n);

// 寄存器全局实用程序过滤器
Object.keys(filters).forEach((key) => {
  Vue.filter(key, filters[key]);
});

// localStorage.clear();
// console.log('测试本地数据库：', db.read().get('settings').value())
const lang = db
  .read()
  .get("settings.lang")
  .value(); // 从本地数据库读取语言设置

const i18n = new VueI18n({
  locale: lang, // 语言标识: zh/en
  fallbackLocale: "en", // 当某个语言不存在时，提供一个默认的语言去处理
  messages, // 导出的语言包，中/英
});
Vue.prototype.$db = db; // this.$db.read().get('xxx').vaule()
Vue.prototype.$totalFloat = 0; // this.$db.read().get('xxx').vaule()
Vue.prototype.$voice = voicePrompt

if (!process.env.IS_WEB) Vue.use(require("vue-electron"));
// Vue.http = Vue.prototype.$http = axios
Vue.config.productionTip = false;

localStorage.clear()
window.ip = "1.1.1.1";
fetch(
  "http://www.net.cn/static/customercare/yourip.asp?t=" + new Date().getTime()
)
  .then((response) => response.text())
  .then((res) => {
    const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
    let ip = reg.exec(res);
    console.log(ip[0]);
    const regex = /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
    if (regex.test(ip[0])) {
      window.ip = ip[0];
    } else {
      window.ip = "1.1.1.1";
    }
  });

/* eslint-disable no-new */
new Vue({
  components: { App },
  router,
  store,
  i18n,
  template: "<App/>",
}).$mount("#app");
